package com.fire.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fire.bo.coupon.res.CouponRes;
import com.fire.bo.other.req.CollectCountReq;
import com.fire.bo.other.res.CollectCountRes;
import com.fire.common.RspObjBean;
import com.fire.service.OtherService;
import com.fire.util.BussinessUtils;
import com.fire.util.ErrRsp;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@CrossOrigin
@RequestMapping("/pc/orther")
@Api(value = "其他", description = "其他")
public class OtherController {
	@Autowired
	private OtherService otherService;

	/**
	 * 收藏数据统计
	 * 
	 * @param reqPersonEntryDateBean
	 * @param bindingResult
	 * @return
	 * @version:v1.0
	 * @author:ZhangPeng
	 * @date:2017年06月02日 上午09:07:14
	 */
	@ApiOperation(value = "收藏数据统计", notes = "收藏数据统计" ,response = CollectCountRes.class)
	@RequestMapping(value = "/findCollectCountList", method = RequestMethod.POST)
	public @ResponseBody RspObjBean findCollectCountList(@RequestBody @Valid CollectCountReq bean, BindingResult bindingResult) {
		// 非空验证
		if (bindingResult.hasErrors()) {
			return BussinessUtils.rspErrorHeadInfo(ErrRsp.PARAM_NULL_CODE,
					bindingResult.getFieldError().getDefaultMessage());
		}

		try {
			List<CollectCountRes> list = otherService.findCollectCountList(bean);
			// 根据上级类别key得到类别集合
			return BussinessUtils.rspErrorHeadInfo(ErrRsp.SUCCESS_CODE, ErrRsp.SUCCESS_CODE_DESC, list,otherService.findCollectCountListCount(bean));
		} catch (Exception e) {
			e.printStackTrace();
			return BussinessUtils.rspErrorHeadInfo(ErrRsp.SYSTEM_ERROR_CODE, ErrRsp.SYSTEM_ERROR_DESC);
		}
	}

	/**
	 * 二维码归类
	 * 
	 * @param reqPersonEntryDateBean
	 * @param bindingResult
	 * @return
	 * @version:v1.0
	 * @author:ZhangPeng
	 * @date:2017年06月02日 上午09:07:14
	 */
	@ApiOperation(value = "二维码归类", notes = "二维码归类")
	@RequestMapping(value = "/userClass", method = RequestMethod.POST)
	public @ResponseBody RspObjBean update(@RequestBody @Valid CouponRes bean, BindingResult bindingResult) {
		// 非空验证
		if (bindingResult.hasErrors()) {
			return BussinessUtils.rspErrorHeadInfo(ErrRsp.PARAM_NULL_CODE,
					bindingResult.getFieldError().getDefaultMessage());
		}

		try {
			//couponService.updateCoupon(bean);
			// 根据上级类别key得到类别集合
			return BussinessUtils.rspErrorHeadInfo(ErrRsp.SUCCESS_CODE, ErrRsp.SUCCESS_CODE_DESC, null);
		} catch (Exception e) {
			e.printStackTrace();
			return BussinessUtils.rspErrorHeadInfo(ErrRsp.SYSTEM_ERROR_CODE, ErrRsp.SYSTEM_ERROR_DESC);
		}
	}

}
